package main

import (
	"context"
	"fmt"
	"log"
	"strconv"
	"time"

	"google.golang.org/grpc"

	pb "gitee.com/aoliang/graceful/graceful_update_grpc/proto"
)

const (
	address = "localhost:50051"
)

func main() {
	for i := 0; i < 10; i++ {
		time.Sleep(2 * time.Second)
		go func(i int) {
			conn, err := grpc.Dial(address, grpc.WithInsecure())
			if err != nil {
				log.Fatalf("did not connect: %v", err)
			}
			defer conn.Close()
			c := pb.NewGreeterClient(conn)

			for j := 0; j < 100; j++ {
				name := "world"
				r, err := c.SayHello(context.Background(), &pb.HelloRequest{Name: name + "-" + strconv.Itoa(i) + "-" + strconv.Itoa(j)})
				if err != nil {
					fmt.Println(err)
					break
				}
				log.Printf("Greeting: %s", r.Message)
				time.Sleep(100 * time.Millisecond)
			}
		}(i)
	}
	time.Sleep(50 * time.Second)
}
